"""
检查数据库中的数据
"""
from database import SessionLocal, StockPrice, TradingSignal
from datetime import datetime, date

def check_database():
    """检查数据库中的数据"""
    db = SessionLocal()
    
    print("="*70)
    print("📊 数据库数据检查")
    print("="*70)
    
    try:
        # 检查股票价格数据
        price_count = db.query(StockPrice).count()
        print(f"\n1️⃣ 股票价格数据: {price_count} 条")
        
        if price_count > 0:
            # 显示最新5条
            latest_prices = db.query(StockPrice).order_by(
                StockPrice.timestamp.desc()
            ).limit(5).all()
            
            print("\n最新5条价格数据:")
            for p in latest_prices:
                date_str = datetime.fromtimestamp(p.timestamp / 1000).strftime('%Y-%m-%d')
                print(f"  {p.symbol}: {date_str} - ¥{p.close:.2f}")
        
        # 检查交易信号数据
        signal_count = db.query(TradingSignal).count()
        print(f"\n2️⃣ 交易信号数据: {signal_count} 条")
        
        if signal_count > 0:
            # 显示今天的信号
            today = date.today()
            today_signals = db.query(TradingSignal).filter(
                TradingSignal.signal_date == today
            ).all()
            
            print(f"\n今天的交易信号 ({len(today_signals)}条):")
            for s in today_signals:
                print(f"  {s.symbol}: {s.signal_type} - 强度{s.strength} - ¥{s.price:.2f}")
                print(f"    理由: {s.reason[:50]}...")
        
        print("\n" + "="*70)
        
    finally:
        db.close()

if __name__ == "__main__":
    check_database()



